#region license
//Copyright 2008 Ritesh Rao 

//Licensed under the Apache License, Version 2.0 (the "License"); 
//you may not use this file except in compliance with the License. 
//You may obtain a copy of the License at 

//http://www.apache.org/licenses/LICENSE-2.0 

//Unless required by applicable law or agreed to in writing, software 
//distributed under the License is distributed on an "AS IS" BASIS, 
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
//See the License for the specific language governing permissions and 
//limitations under the License. 
#endregion

using System.Collections.Generic;
using System.Linq;

namespace LinqRepositorySample.Domain
{
    /// <summary>
    /// The <see cref="IRepository{T}"/> interface defines a standard contract that repository
    /// components should implement.
    /// </summary>
    /// <typeparam name="T">The type of entity that the repository encapsulates.</typeparam>
    public interface IRepository<T> : IQueryable<T>
    {
        /// <summary>
        /// Marks the entity instance to be saved to the store.
        /// </summary>
        /// <param name="entity">An instance of <typeparamref name="T"/> that should be saved
        /// to the database.</param>
        /// <remarks>Implementors of this method must handle both Insert and Update scenarios.</remarks>
        void Save(T entity);

        /// <summary>
        /// Marks the entity instance to be deleted from the store.
        /// </summary>
        /// <param name="entity">An instance of <typeparamref name="T"/> that should be deleted.</param>
        void Delete(T entity);

        /// <summary>
        /// Querries the repository based on the provided specification and returns results that
        /// are only satisfied by the specification.
        /// </summary>
        /// <param name="specification">A <see cref="ISpecification{T}"/> instnace used to filter results
        /// that only satisfy the specification.</param>
        /// <returns>A <see cref="IEnumerable{T}"/> that can be used to enumerate over the results
        /// of the query.</returns>
        IEnumerable<T> Query(ISpecification<T> specification);
    }
}